package org.xtense.rcp.editors.util;

import java.util.List;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.xtense.util.StringUtil;

public class DatabaseTableProvider implements IStructuredContentProvider,
		ITableLabelProvider {

	@SuppressWarnings("unchecked")
	@Override
	public Object[] getElements(Object inputElement) {
		if (inputElement instanceof List) {
			return ((List) inputElement).toArray();
		} else {
			return new Object[0];
		}
	}

	@Override
	public void dispose() {
		//do nothing

	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		//do nothing

	}

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		// TODO 
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		TableEntry e = (TableEntry) element;
		if (columnIndex == 0)
			return StringUtil.append(new Object[] { e.getId() });
		else if (columnIndex == 1)
			return e.getName();
		else if (columnIndex == 2)
			return e.getTime();
		else
			return null;
	}

	@Override
	public void addListener(ILabelProviderListener listener) {
		//do nothing

	}

	@Override
	public boolean isLabelProperty(Object element, String property) {
		//do nothing
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener listener) {
		//do nothing

	}

}
